package com.lagou.bootPro.registration;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @ClassName ServletRegistrationBean
 * @Description
 * @Author playboy serlvet的注册bean，为什么要有这个bean，因为他要实现ServletContainerInitializer接口，并且要持有servlet
 * @Date 2021/5/15 7:35 下午
 * @Version 1.0
 **/
public class MyServletRegistrationBean implements MyServletContextInitializer {

	private Servlet servlet;

	public MyServletRegistrationBean(Servlet servlet) {
		this.servlet = servlet;
	}

	@Override
	public void onStartup(ServletContext ctx) throws ServletException {
		ServletRegistration.Dynamic registration = ctx.addServlet("app", servlet);
		//设置启动加载
		registration.setLoadOnStartup(1);
		registration.addMapping("/app/*");
	}
}
